
#ifndef UM_WIN32_REGISTRY_H
#define UM_WIN32_REGISTRY_H


template <int TKey>
class RegKeyBasic {

public:

	static bool deleteKey(LPCTSTR lpSubKey) {
		return (RegDeleteKey(TKey, lpSubKey) == ERROR_SUCCESS);
	}

	static createKey(LPCTSTR subkey, 

};

class RegistryKey {

public:

	RegistryKey(HKEY hKey) {
		m_hKey = hKey;
	}

	~RegistryKey() {
		closeKey();
	}

	RegistryKey createKey(LPCTSTR lpSubKey) {
		HEKY hKey = NULL;
		DWORD dwDisposition;
		LONG lRet = RegCreateKeyEx(
			m_hKey,
			lpSubKey,
			NULL,
			NULL,
			REG_OPTION_NON_VOLATILE,
			KEY_ALL_ACCESS,
			NULL,
			&hKey,
			&dwDisposition
		);
		return RegistryKey(hKey);
	}

	RegistryKey openKey(LPCTSTR lpSubKey) {
		HEKY hKey = NULL;
		LONG lRet = RegOpenKeyEx(
			m_hKey,
			lpSubKey,
			0,
			KEY_ALL_ACCESS,
			&hKey
		);
		return RegistryKey(hKey);
	}

	bool closeKey() {
		if (m_hKey != NULL) {
			RegCloseKey(m_hKey);
			m_hKey = NULL;
		}
		return true;
	}

	DWORD readInteger(LPCTSTR lpValueName) {
		DWORD dwValue;
		DWORD cbData = sizeof(DWORD);
		LONG lRet = RegQueryValueEx(
			m_hKey,
			lpValueName,
			NULL,
			NULL,
			&dwValue,
			&cbData
		);
		return (lRet == ERROR_SUCCESS && cbData == sizeof(DWORD));
	}


private:

	HEKY	m_hKey;

};

class Registry {

public:

	/**
	* Contains the configuration data for the local machine. 
	* This field reads the Windows registry base key HKEY_LOCAL_MACHINE.
	*/
	typedef RegKeyBasic<HKEY_LOCAL_MACHINE> LocalMachine;

	/**
	* Contains information about the current user preferences. 
	* This field reads the Windows registry base key HKEY_CURRENT_USER.
	*/
	typedef RegKeyBasic<HKEY_CURRENT_USER>  CurrentUser;

	/**
	* Defines the types (or classes) of documents and the 
	* properties associated with those types. This field reads 
	* the Windows registry base key HKEY_CLASSES_ROOT.
	*/
	typedef RegKeyBasic<HKEY_CLASSES_ROOT>  ClassRoot;

	/**
	* Contains information about the default user configuration. 
	* This field reads the Windows registry base key HKEY_USERS.
	*/
	typedef RegKeyBasic<HKEY_USERS>         Users;
};

#endif // UM_WIN32_REGISTRY_H